from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAdminUser
from meiduo_admin.serializers.skus import SKUImageModelSerializer, SKUModelSerializer
from goods.models import SKUImage, SKU
from rest_framework.viewsets import ModelViewSet
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import permission_required


@method_decorator(permission_required('goods.list_skuimage_api', raise_exception=True), name='list')
@method_decorator(permission_required('goods.create_skuimage_api', raise_exception=True), name='create')
@method_decorator(permission_required('goods.retrieve_skuimage_api', raise_exception=True), name='retrieve')
@method_decorator(permission_required('goods.update_skuimage_api', raise_exception=True), name='update')
@method_decorator(permission_required('goods.delete_skuimage_api', raise_exception=True), name='destroy')
class SKUImageView(ModelViewSet):
    serializer_class = SKUImageModelSerializer
    queryset = SKUImage.objects.all()
    permission_classes = [IsAdminUser]
    lookup_value_regex = '\d+'


class SKUSimpleView(ListAPIView):
    serializer_class = SKUModelSerializer
    queryset = SKU.objects.all()
    permission_classes = [IsAdminUser]
    pagination_class = None
